﻿using System;
using System.Collections.Generic;
using System.IO;

namespace rkill {
    class Program {
        private const string USAGE = "Usage is: rkill \"path to source\" [-v]. -v activates Verbose mode (default is quiet).";
        private const string VERBOSE = "-v";

        static void Main(string[] args) {
            Params p = GetParameters(args);
            Logger.IsVerbose = p.Verbose;

            Logger.InfoLine("Killing regions below " + p.RootPath);

            RegionKiller.KillRegionsBelow(p.RootPath);

            Logger.VerboseLine("Altered " + Effects.FilesAltered + " files.");
            Logger.VerboseLine("Killed " + Effects.RegionsKilled + " regions.");

            Logger.InfoLine("Done.");
        }

        private static Params GetParameters(string[] args) {
            if (args.Length < 1) {
                throw new ArgumentException("You called rkill without parameters. " + USAGE, "args");
            }

            string path = args[0];
            if (!Directory.Exists(path)) {
                throw new ArgumentException(
                    String.Format("You called rkill with path = \"{0}\", which is not a valid directory. {1}", path, USAGE),
                    "args");
            }

            string v = String.Empty;
            if (args.Length > 1) {
                v = args[1];
                if (v != VERBOSE) {
                    Console.Out.WriteLine(String.Format("Unrecognized parameter {0}. {1} Assuming quite mode.", v, USAGE));
                }
            }
            
            Params res = new Params() { RootPath = Path.GetFullPath(path), Verbose = v == VERBOSE };
            return res;
        }
    }
}
